﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
namespace WPFExcelReport
{
    public partial class TSVA02 
    {
     
        #region ==dwVAK===========
        public static readonly DependencyProperty dwVAKProperty = DependencyProperty.Register("dwVAK",
            typeof(DataRow), typeof(TSVA02),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwVAKChanged));
        public DataRow dwVAK
        {
            get
            {
                return ((VVAKOLL)MV).dwVAK;
            }
            set
            {
                SetValue(dwVAKProperty, value);
                ((VVAKOLL)MV).dwVAK = value;
            }
        }
        private static void OndwVAKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TSVA02;
            if (src != null)
            {
                src.dwVAK = (DataRow)e.NewValue;
            }
        }
        #endregion
   
        public TSVA02()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return; 
            MV = new VVAKOLL();
            DataContext = MV; 
            InitializeComponent();   
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwVAK = dwMaster;
            if (dwMaster == null)
            {
                KEY = "";
            }
            else
            {
                KEY = dwMaster["VAKKOLL"].ToString();
            }
        }
     
        public override void LOADALL()
        {
            dwData = TBMain.NewRow();
            dwData["VAKMANDANT"] = app.Mandant;
            dwData["VAKKM1"] = KM1.PadRight(5);
            SResult = TMV.QVAK_1(dwData);
            MergeData(SResult,false);
        } 
        public override void LOADBYAUF()
        {
            Locate("VAKKOLL",ORDERNUM);
            base.LOADBYAUF();
        }
        public override void ComboBox_DropDownOpened(object sender, EventArgs e)
        { 
            base.ComboBox_DropDownOpened(sender, e);
        }
        public override void ManageCommand(object sender, RoutedEventArgs e)
        {
            if (IsManage)
            {
                LOADALL();
            }
            else
            {
                VICC_WFEVENTS.SVWF.VA02(RUNID); 
            }
            base.ManageCommand(sender, e);
        }
        public override void OnAppModeChg()
        {
            base.OnAppModeChg();
            LOADALL();
        } 
    }
}
